package org.ws.task.zookeeper;

public class ZkConfig {

    private String namespace;

    private String address;

    private int sessionTimeout = 60_000;

    private int connectionTimeout = 15_000;

    private boolean enableCompression = true;

    private boolean enableAcl = false;

    private String user;

    private String pwd;

    private String authScheme = "digest";

    public String getNamespace() {
        return namespace;
    }

    public String getAddress() {
        return address;
    }

    public int getSessionTimeout() {
        return sessionTimeout;
    }

    public int getConnectionTimeout() {
        return connectionTimeout;
    }

    public boolean isEnableCompression() {
        return enableCompression;
    }

    public boolean isEnableAcl() {
        return enableAcl;
    }

    public String getUser() {
        return user;
    }

    public String getPwd() {
        return pwd;
    }

    public String getAuthScheme() {
        return authScheme;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setSessionTimeout(int sessionTimeout) {
        this.sessionTimeout = sessionTimeout;
    }

    public void setConnectionTimeout(int connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    public void setEnableCompression(boolean enableCompression) {
        this.enableCompression = enableCompression;
    }

    public void setEnableAcl(boolean enableAcl) {
        this.enableAcl = enableAcl;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public void setAuthScheme(String authScheme) {
        this.authScheme = authScheme;
    }

    public static ZkConfigBuilder builder(){
        return new ZkConfigBuilder();
    }

    public static final class ZkConfigBuilder {
        private String namespace = "app";
        private String connect;
        private int sessionTimeout = 60_000;
        private int connectionTimeout = 15_000;
        private boolean enableCompression = true;
        private boolean enableAcl = false;
        private String user;
        private String pwd;
        private String authScheme = "digest";

        private ZkConfigBuilder() {
        }

        public ZkConfigBuilder namespace(String namespace) {
            this.namespace = namespace;
            return this;
        }

        public ZkConfigBuilder connect(String connect) {
            this.connect = connect;
            return this;
        }

        public ZkConfigBuilder sessionTimeout(int sessionTimeout) {
            this.sessionTimeout = sessionTimeout;
            return this;
        }

        public ZkConfigBuilder connectionTimeout(int connectionTimeout) {
            this.connectionTimeout = connectionTimeout;
            return this;
        }

        public ZkConfigBuilder enableCompression(boolean enableCompression) {
            this.enableCompression = enableCompression;
            return this;
        }

        public ZkConfigBuilder enableAcl(boolean enableAcl) {
            this.enableAcl = enableAcl;
            return this;
        }

        public ZkConfigBuilder user(String user) {
            this.user = user;
            return this;
        }

        public ZkConfigBuilder pwd(String pwd) {
            this.pwd = pwd;
            return this;
        }

        public ZkConfigBuilder authScheme(String authScheme) {
            this.authScheme = authScheme;
            return this;
        }


        public ZkConfig build() {
            ZkConfig zkConfig = new ZkConfig();
            zkConfig.namespace = this.namespace;
            zkConfig.pwd = this.pwd;
            zkConfig.address = this.connect;
            zkConfig.user = this.user;
            zkConfig.authScheme = this.authScheme;
            zkConfig.enableAcl = this.enableAcl;
            zkConfig.enableCompression = this.enableCompression;
            zkConfig.sessionTimeout = this.sessionTimeout;
            zkConfig.connectionTimeout = this.connectionTimeout;
            return zkConfig;
        }
    }
}
